package com.deng.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deng.api.entity.CloudCompany;
import com.deng.api.mapper.CloudCityMapper;
import com.deng.api.mapper.CloudCompanyMapper;
import com.deng.api.service.ICloudCompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deng.api.vo.PageVO;
import com.deng.commons.common.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author deng
 * @since 2022-08-10
 */
@Service
public class CloudCompanyServiceImpl extends ServiceImpl<CloudCompanyMapper, CloudCompany> implements ICloudCompanyService {
    @Resource
    private CloudCompanyMapper cloudCompanyMapper;

    @Override
    public BaseResult getCompanies(Integer page, Integer size, CloudCompany cloudCompany) {
        Page<CloudCompany> p = new Page<>(page,size);
        //根据公司名查询
        LambdaQueryWrapper<CloudCompany> wrapper = new LambdaQueryWrapper();
        if (!StrUtil.isEmptyIfStr(cloudCompany.getName())){
            wrapper.eq(CloudCompany::getName,cloudCompany.getName());
        }
        Page<CloudCompany> companyPage = cloudCompanyMapper.selectPage(p, wrapper);
        return BaseResult.success(new PageVO<>(companyPage.getRecords(), companyPage.getTotal()));
    }
}
